{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cross-entropy (CE) Method Test on Discrete Output\n",
    "with Categorical distribution\n",
    "\n",
    "Tips:\n",
    "* N*ratio should not be too small, especially at the beginning, otherwise it will converge fast for categorical distribution, which may lead to sub-optimal."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "true min:  -4.957734573741763e-05\n",
      "[0.12, 0.0, 0.0, 0.08, 0.04, 0.12, 0.0, 0.08, 0.0, 0.0, 0.04, 0.0, 0.04, 0.16, 0.0, 0.04, 0.0, 0.04, 0.08, 0.0, 0.0, 0.08, 0.04, 0.0, 0.0, 0.04, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
      "[0.24, 0.0, 0.0, 0.16, 0.08, 0.2, 0.0, 0.16, 0.0, 0.0, 0.04, 0.0, 0.08, 0.04, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
      "[0.56, 0.0, 0.0, 0.24, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n",
      "[1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QR3ydeGua5bgS8Df+CcaxtgnUhtr8H8/msJvncg+F56eaBAGylen8aDwD7n3HcGWGdib9+HmS0h+DkQ1tAa5N9lLfAJ76ilZUBzSJNKuA249+7H9goR+h4a6HPoReBmMxvvNQHf7C0bnnD3wPt1IfihVgN0AHXAiyH3fY3gkSZvA7eFLH8BmOxdn04wNCqAp4DUMNX5U+Cz5y2bDLwQUscO77KHYPNKuLfdI8AuYKf35px0fl3e7dsJHg1zKEJ1VRBsW93uXX54fl2R3F79/f7ANwiGF0Ca996p8N5L0yOwja4h2By4M2Q73Q58tvd9BtzjbZsdBDv23xOBuvr9u5xXlwH/5W3PXYQcZRjm2sYS/LDPClkW8e1FMJyOAV3eZ9enCPZRvQQcBH4H5HjrlgE/DnnsJ733WQXwZyNRj86QFhGRPuKxWUlERC5C4SAiIn0oHEREpA+Fg4iI9KFwEBGRPhQOIiLSh8JBRET6UDiIiEgf/x8ZOWwd+lZirwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "from torch.distributions import Categorical\n",
    "\n",
    "# Hyperparameters\n",
    "N=50  # number of samples for each iteration\n",
    "ratio=0.5  # select top ratio% samples wrt f(x)\n",
    "num_itr=5  # iterations of CEM\n",
    "x_dim=50  # dimension of x\n",
    "\n",
    "f=lambda x: 3*x**2+x**4+1  # the score function, evaluate how good is x\n",
    "\n",
    "# In this example we try to find minimal of score value, we give the ground truth using continuous value samples\n",
    "samples = np.random.normal(0,1,1000) # x-value of f(x)\n",
    "print('true min: ', samples[np.argmin(f(samples))])\n",
    "\n",
    "# the categorical distribution for generating x\n",
    "dist=Categorical(torch.tensor(x_dim*[1./x_dim]))\n",
    "num_selected = int(N*ratio)  # how many samples are selected according to the ratio\n",
    "\n",
    "for i in range(num_itr):\n",
    "    # sample\n",
    "    x=dist.sample((N,)).numpy()\n",
    "    # select top ratio% (max [-a:]or min [:a])\n",
    "    selected_samples = x[np.array(f(x)).argsort()[:num_selected]]\n",
    "    # count selected samples \n",
    "    counts = [np.count_nonzero(selected_samples==i) for i in range(x_dim)]\n",
    "    # get probability list of selected samples distribution\n",
    "    prob_list = (np.array(counts)/float(num_selected)).tolist()\n",
    "    # re-fit the categorical distribution\n",
    "    dist = Categorical(torch.tensor(prob_list))\n",
    "    \n",
    "    print(prob_list)\n",
    "\n",
    "# show the shape of function f(x)\n",
    "x=np.linspace(-10,10,N)\n",
    "y=f(x)\n",
    "plt.plot(x,y)\n",
    "plt.show()\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Soft update"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "true min:  9.083741204886473e-05\n",
      "[0.03 0.05 0.03 0.07 0.03 0.05 0.01 0.07 0.01 0.03 0.03 0.05 0.01 0.05\n",
      " 0.03 0.03 0.01 0.01 0.03 0.07 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01\n",
      " 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01\n",
      " 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01]\n",
      "[0.015 0.025 0.015 0.115 0.055 0.125 0.005 0.095 0.045 0.055 0.055 0.085\n",
      " 0.005 0.065 0.015 0.015 0.005 0.005 0.015 0.035 0.005 0.005 0.005 0.005\n",
      " 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005\n",
      " 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005 0.005\n",
      " 0.005 0.005]\n",
      "[0.0275 0.0525 0.0075 0.1575 0.0875 0.2025 0.0025 0.1875 0.0225 0.0275\n",
      " 0.0275 0.0425 0.0025 0.0325 0.0075 0.0075 0.0025 0.0025 0.0075 0.0175\n",
      " 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025\n",
      " 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025\n",
      " 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025 0.0025]\n",
      "[0.07375 0.08625 0.00375 0.27875 0.12375 0.20125 0.00125 0.09375 0.01125\n",
      " 0.01375 0.01375 0.02125 0.00125 0.01625 0.00375 0.00375 0.00125 0.00125\n",
      " 0.00375 0.00875 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125\n",
      " 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125\n",
      " 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125 0.00125\n",
      " 0.00125 0.00125 0.00125 0.00125 0.00125]\n",
      "[0.056875 0.143125 0.001875 0.419375 0.161875 0.100625 0.000625 0.046875\n",
      " 0.005625 0.006875 0.006875 0.010625 0.000625 0.008125 0.001875 0.001875\n",
      " 0.000625 0.000625 0.001875 0.004375 0.000625 0.000625 0.000625 0.000625\n",
      " 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625\n",
      " 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625\n",
      " 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625 0.000625\n",
      " 0.000625 0.000625]\n",
      "[8.843750e-02 2.115625e-01 9.375000e-04 5.096875e-01 8.093750e-02\n",
      " 5.031250e-02 3.125000e-04 2.343750e-02 2.812500e-03 3.437500e-03\n",
      " 3.437500e-03 5.312500e-03 3.125000e-04 4.062500e-03 9.375000e-04\n",
      " 9.375000e-04 3.125000e-04 3.125000e-04 9.375000e-04 2.187500e-03\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04\n",
      " 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04 3.125000e-04]\n",
      "[1.2421875e-01 3.6578125e-01 4.6875000e-04 4.1484375e-01 4.0468750e-02\n",
      " 2.5156250e-02 1.5625000e-04 1.1718750e-02 1.4062500e-03 1.7187500e-03\n",
      " 1.7187500e-03 2.6562500e-03 1.5625000e-04 2.0312500e-03 4.6875000e-04\n",
      " 4.6875000e-04 1.5625000e-04 1.5625000e-04 4.6875000e-04 1.0937500e-03\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04\n",
      " 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04 1.5625000e-04]\n",
      "[1.22109375e-01 4.62890625e-01 2.34375000e-04 3.67421875e-01\n",
      " 2.02343750e-02 1.25781250e-02 7.81250000e-05 5.85937500e-03\n",
      " 7.03125000e-04 8.59375000e-04 8.59375000e-04 1.32812500e-03\n",
      " 7.81250000e-05 1.01562500e-03 2.34375000e-04 2.34375000e-04\n",
      " 7.81250000e-05 7.81250000e-05 2.34375000e-04 5.46875000e-04\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05 7.81250000e-05 7.81250000e-05\n",
      " 7.81250000e-05 7.81250000e-05]\n",
      "[1.41054687e-01 6.51445312e-01 1.17187500e-04 1.83710938e-01\n",
      " 1.01171875e-02 6.28906250e-03 3.90625000e-05 2.92968750e-03\n",
      " 3.51562500e-04 4.29687500e-04 4.29687500e-04 6.64062500e-04\n",
      " 3.90625000e-05 5.07812500e-04 1.17187500e-04 1.17187500e-04\n",
      " 3.90625000e-05 3.90625000e-05 1.17187500e-04 2.73437500e-04\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05 3.90625000e-05 3.90625000e-05\n",
      " 3.90625000e-05 3.90625000e-05]\n",
      "[1.70527344e-01 7.25722656e-01 5.85937500e-05 9.18554688e-02\n",
      " 5.05859375e-03 3.14453125e-03 1.95312500e-05 1.46484375e-03\n",
      " 1.75781250e-04 2.14843750e-04 2.14843750e-04 3.32031250e-04\n",
      " 1.95312500e-05 2.53906250e-04 5.85937500e-05 5.85937500e-05\n",
      " 1.95312500e-05 1.95312500e-05 5.85937500e-05 1.36718750e-04\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05 1.95312500e-05 1.95312500e-05\n",
      " 1.95312500e-05 1.95312500e-05]\n",
      "[2.85263672e-01 6.62861328e-01 2.92968750e-05 4.59277344e-02\n",
      " 2.52929687e-03 1.57226563e-03 9.76562500e-06 7.32421875e-04\n",
      " 8.78906250e-05 1.07421875e-04 1.07421875e-04 1.66015625e-04\n",
      " 9.76562500e-06 1.26953125e-04 2.92968750e-05 2.92968750e-05\n",
      " 9.76562500e-06 9.76562500e-06 2.92968750e-05 6.83593750e-05\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06 9.76562500e-06 9.76562500e-06\n",
      " 9.76562500e-06 9.76562500e-06]\n",
      "[4.62631836e-01 5.11430664e-01 1.46484375e-05 2.29638672e-02\n",
      " 1.26464844e-03 7.86132813e-04 4.88281250e-06 3.66210938e-04\n",
      " 4.39453125e-05 5.37109375e-05 5.37109375e-05 8.30078125e-05\n",
      " 4.88281250e-06 6.34765625e-05 1.46484375e-05 1.46484375e-05\n",
      " 4.88281250e-06 4.88281250e-06 1.46484375e-05 3.41796875e-05\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06 4.88281250e-06 4.88281250e-06\n",
      " 4.88281250e-06 4.88281250e-06]\n",
      "[7.31315918e-01 2.55715332e-01 7.32421875e-06 1.14819336e-02\n",
      " 6.32324219e-04 3.93066406e-04 2.44140625e-06 1.83105469e-04\n",
      " 2.19726562e-05 2.68554688e-05 2.68554688e-05 4.15039062e-05\n",
      " 2.44140625e-06 3.17382813e-05 7.32421875e-06 7.32421875e-06\n",
      " 2.44140625e-06 2.44140625e-06 7.32421875e-06 1.70898437e-05\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06 2.44140625e-06 2.44140625e-06\n",
      " 2.44140625e-06 2.44140625e-06]\n",
      "[8.65657959e-01 1.27857666e-01 3.66210937e-06 5.74096680e-03\n",
      " 3.16162109e-04 1.96533203e-04 1.22070313e-06 9.15527344e-05\n",
      " 1.09863281e-05 1.34277344e-05 1.34277344e-05 2.07519531e-05\n",
      " 1.22070313e-06 1.58691406e-05 3.66210937e-06 3.66210937e-06\n",
      " 1.22070313e-06 1.22070313e-06 3.66210937e-06 8.54492187e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06 1.22070313e-06 1.22070313e-06\n",
      " 1.22070313e-06 1.22070313e-06]\n",
      "[9.32828979e-01 6.39288330e-02 1.83105469e-06 2.87048340e-03\n",
      " 1.58081055e-04 9.82666016e-05 6.10351563e-07 4.57763672e-05\n",
      " 5.49316406e-06 6.71386719e-06 6.71386719e-06 1.03759766e-05\n",
      " 6.10351563e-07 7.93457031e-06 1.83105469e-06 1.83105469e-06\n",
      " 6.10351563e-07 6.10351563e-07 1.83105469e-06 4.27246094e-06\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07 6.10351563e-07 6.10351563e-07\n",
      " 6.10351563e-07 6.10351563e-07]\n",
      "[9.66414490e-01 3.19644165e-02 9.15527344e-07 1.43524170e-03\n",
      " 7.90405273e-05 4.91333008e-05 3.05175781e-07 2.28881836e-05\n",
      " 2.74658203e-06 3.35693359e-06 3.35693359e-06 5.18798828e-06\n",
      " 3.05175781e-07 3.96728516e-06 9.15527344e-07 9.15527344e-07\n",
      " 3.05175781e-07 3.05175781e-07 9.15527344e-07 2.13623047e-06\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07 3.05175781e-07 3.05175781e-07\n",
      " 3.05175781e-07 3.05175781e-07]\n",
      "[9.83207245e-01 1.59822083e-02 4.57763672e-07 7.17620850e-04\n",
      " 3.95202637e-05 2.45666504e-05 1.52587891e-07 1.14440918e-05\n",
      " 1.37329102e-06 1.67846680e-06 1.67846680e-06 2.59399414e-06\n",
      " 1.52587891e-07 1.98364258e-06 4.57763672e-07 4.57763672e-07\n",
      " 1.52587891e-07 1.52587891e-07 4.57763672e-07 1.06811523e-06\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07 1.52587891e-07 1.52587891e-07\n",
      " 1.52587891e-07 1.52587891e-07]\n",
      "[9.91603622e-01 7.99110413e-03 2.28881836e-07 3.58810425e-04\n",
      " 1.97601318e-05 1.22833252e-05 7.62939453e-08 5.72204590e-06\n",
      " 6.86645508e-07 8.39233398e-07 8.39233398e-07 1.29699707e-06\n",
      " 7.62939453e-08 9.91821289e-07 2.28881836e-07 2.28881836e-07\n",
      " 7.62939453e-08 7.62939453e-08 2.28881836e-07 5.34057617e-07\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08 7.62939453e-08 7.62939453e-08\n",
      " 7.62939453e-08 7.62939453e-08]\n",
      "[9.95801811e-01 3.99555206e-03 1.14440918e-07 1.79405212e-04\n",
      " 9.88006592e-06 6.14166260e-06 3.81469727e-08 2.86102295e-06\n",
      " 3.43322754e-07 4.19616699e-07 4.19616699e-07 6.48498535e-07\n",
      " 3.81469727e-08 4.95910645e-07 1.14440918e-07 1.14440918e-07\n",
      " 3.81469727e-08 3.81469727e-08 1.14440918e-07 2.67028809e-07\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08 3.81469727e-08 3.81469727e-08\n",
      " 3.81469727e-08 3.81469727e-08]\n",
      "[9.97900906e-01 1.99777603e-03 5.72204590e-08 8.97026062e-05\n",
      " 4.94003296e-06 3.07083130e-06 1.90734863e-08 1.43051147e-06\n",
      " 1.71661377e-07 2.09808350e-07 2.09808350e-07 3.24249268e-07\n",
      " 1.90734863e-08 2.47955322e-07 5.72204590e-08 5.72204590e-08\n",
      " 1.90734863e-08 1.90734863e-08 5.72204590e-08 1.33514404e-07\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08 1.90734863e-08 1.90734863e-08\n",
      " 1.90734863e-08 1.90734863e-08]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAD8CAYAAACcjGjIAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3Xl0XGd9//H3V7tlyZK1WLYl2fIiO17iJVFsB2cjsbMBdWiBpkBwC9RQkpalPRR+tKSHlB7oAi20hAYSCGnICklMGggmCUmcxIu8r7FlR7Ik27JkS7IsWes8vz/myp1Yki1Lmrkzms/rnDmauXNn5qur0XzmPs+9z2POOUREREIl+F2AiIhEH4WDiIj0oXAQEZE+FA4iItKHwkFERPpQOIiISB8KBxER6UPhICIifSgcRESkjyS/CxiqvLw8V1JS4ncZIiIxY8uWLQ3OufzBrBuz4VBSUkJ5ebnfZYiIxAwzqxrsumpWEhGRPhQOIiLSh8JBRET6UDiIiEgfCgcREelD4SAiIn0oHEREpI+4CofO7gD3//4Qrx2o97sUEZFL9ru9dTzw2i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+HmS0h+DkQ1tAa5N9lLfAJ76ilZUBzSJNKuA249+7H9goR+h4a6HPoReBmMxvvNQHf7C0bnnD3wPt1IfihVgN0AHXAiyH3fY3gkSZvA7eFLH8BmOxdn04wNCqAp4DUMNX5U+Cz5y2bDLwQUscO77KHYPNKuLfdI8AuYKf35px0fl3e7dsJHg1zKEJ1VRBsW93uXX54fl2R3F79/f7ANwiGF0Ca996p8N5L0yOwja4h2By4M2Q73Q58tvd9BtzjbZsdBDv23xOBuvr9u5xXlwH/5W3PXYQcZRjm2sYS/LDPClkW8e1FMJyOAV3eZ9enCPZRvQQcBH4H5HjrlgE/DnnsJ733WQXwZyNRj86QFhGRPuKxWUlERC5C4SAiIn0oHEREpA+Fg4iI9KFwEBGRPhQOIiLSh8JBRET6UDiIiEgf/x8ZOWwd+lZirwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "from torch.distributions import Categorical\n",
    "\n",
    "# Hyperparameters\n",
    "N=50  # number of samples for each iteration\n",
    "ratio=0.5  # select top ratio% samples wrt f(x)\n",
    "num_itr=20  # iterations of CEM\n",
    "x_dim=50  # dimension of x\n",
    "alpha = 0.5 # soft update parameter\n",
    "\n",
    "f=lambda x: 3*x**2+x**4+1  # the score function, evaluate how good is x\n",
    "\n",
    "# In this example we try to find minimal of score value, we give the ground truth using continuous value samples\n",
    "samples = np.random.normal(0,1,1000) # x-value of f(x)\n",
    "print('true min: ', samples[np.argmin(f(samples))])\n",
    "\n",
    "# the categorical distribution for generating x\n",
    "last_prob_list = x_dim*[1./x_dim]\n",
    "dist=Categorical(torch.tensor(last_prob_list))\n",
    "num_selected = int(N*ratio)  # how many samples are selected according to the ratio\n",
    "\n",
    "for i in range(num_itr):\n",
    "    # sample\n",
    "    x=dist.sample((N,)).numpy()\n",
    "    # select top ratio% (max [-a:]or min [:a])\n",
    "    selected_samples = x[np.array(f(x)).argsort()[:num_selected]]\n",
    "    # count selected samples \n",
    "    counts = [np.count_nonzero(selected_samples==i) for i in range(x_dim)]\n",
    "    # get probability list of selected samples distribution\n",
    "    prob_list = (np.array(counts)/float(num_selected)).tolist()\n",
    "    prob_list = alpha*np.array(prob_list)+(1.-alpha)*np.array(last_prob_list)\n",
    "    # re-fit the categorical distribution\n",
    "    dist = Categorical(torch.tensor(prob_list))\n",
    "    # update last\n",
    "    last_prob_list = prob_list\n",
    "    \n",
    "    print(prob_list)\n",
    "\n",
    "# show the shape of function f(x)\n",
    "x=np.linspace(-10,10,N)\n",
    "y=f(x)\n",
    "plt.plot(x,y)\n",
    "plt.show()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
